<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <link rel="stylesheet" href="styles/style.css">
        <link rel="stylesheet" href="styles/theme/atom-one-dark.css">
        <title>例子17-JS进阶（二）</title>
    </head>
    <body>
        <pre>
            <code>
                    // 例子17

                    var array = [1, 3, 'h', 5, 'm', '4'];
                    var res = [];
                    for(var i = 0; i < array.length; i ++) {
                        if (typeof array[i] === 'number') {
                            res.push(array[i]);
                        }
                    }

                    function getNumbers(array) {
                        var res = [];
                        array.forEach(function(item) {
                            if (typeof item === 'number') {
                                res.push(item);
                            }
                        })
                        return res;
                    }

                    var array = [1, 3, 'h', 5, 'm', '4'];
                    var res = getNumbers(array);
            </code>
        </pre>
        <script src="scripts/libs/highlight.pack.js"></script>
        <script src="scripts/17.js"></script>
        <script>
            hljs.initHighlightingOnLoad();
        </script>
    </body>
</html>